package com.huaxin.device.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.huaxin.device.dto.ResponseResult;
import com.huaxin.device.dto.request.EquipmentModelCreateReqDTO;
import com.huaxin.device.dto.request.EquipmentModelPageListReqDTO;
import com.huaxin.device.dto.request.EquipmentModelUpdateReqDTO;
import com.huaxin.device.models.EquipmentModel;
import com.huaxin.device.service.EquipmentModelService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.validation.Valid;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

@Tag(name = "电力设备型号")
@RestController
@RequiredArgsConstructor
@RequestMapping("/v1/device/equipmentModel")
public class EquipmentModelController {

    private final EquipmentModelService service;

    @Operation(summary = "创建电力设备型号", description = "创建电力设备型号")
    @PostMapping("/create")
    public ResponseResult<EquipmentModel> create(@RequestBody @Valid EquipmentModelCreateReqDTO in) {
        return service.create(in);
    }

    @Operation(summary = "获取电力设备型号", description = "根据ID获取电力设备型号")
    @GetMapping("/get")
    public ResponseResult<EquipmentModel> get(
            @Parameter(description = "型号ID", example = "876e5432-e12d-32c1-b654-321098765432")
            @RequestParam(value = "id", required = true) String id) {
        EquipmentModel entity = service.getByModelId(id);
        return ResponseResult.ok(entity);
    }

    @Operation(summary = "更新电力设备型号", description = "更新电力设备型号")
    @PostMapping("/update")
    public ResponseResult<String> update(@RequestBody @Valid EquipmentModelUpdateReqDTO in) {
        return service.update(in);
    }

    @Operation(summary = "删除电力设备型号", description = "删除电力设备型号（逻辑删除）")
    @DeleteMapping("/{id}/delete")
    public ResponseResult<String> delete(
            @Parameter(description = "型号ID", example = "876e5432-e12d-32c1-b654-321098765432")
            @PathVariable String id) {
        return service.delete(id);
    }

    @Operation(summary = "启用电力设备型号", description = "启用设备型号")
    @GetMapping("/active")
    public ResponseResult<String> active(
            @Parameter(description = "型号ID", example = "876e5432-e12d-32c1-b654-321098765432")
            @RequestParam(value = "id", required = true) String id) {
        return service.active(id);
    }

    @Operation(summary = "禁用电力设备型号", description = "禁用设备型号")
    @GetMapping("/inactive")
    public ResponseResult<String> inactive(
            @Parameter(description = "型号ID", example = "876e5432-e12d-32c1-b654-321098765432")
            @RequestParam(value = "id", required = true) String id) {
        return service.inactive(id);
    }

    @Operation(summary = "分页查询电力设备型号", description = "分页查询电力设备型号")
    @PostMapping("/page")
    public ResponseResult<IPage<EquipmentModel>> pageQuery(@RequestBody @Valid EquipmentModelPageListReqDTO in) {
        return service.pageQuery(in);
    }
}